home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 2.4 KB | 84 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: SLLocale.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef SLLOCALE_H
- #include "SLLocale.h"
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__SCRIPT__)
- #include <Script.h>
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment Strings
- #endif
-
- //========================================================================================
- // FW_MacScriptIsSingleByte
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- static FW_Boolean FW_MacScriptIsSingleByte(short script)
- {
- static short gCachedScriptCode = smRoman;
- static long gCachedScriptIsSingleByte = true;
- if (script != gCachedScriptCode)
- {
- gCachedScriptCode = script;
- long flags = GetScriptVariable(script, smScriptFlags);
- gCachedScriptIsSingleByte = (flags & (1L<<smsfSingByte))!=0;
- }
- return gCachedScriptIsSingleByte;
- }
- #endif
-
- //========================================================================================
- // FW_LocaleIsSingleByte
- //========================================================================================
-
- FW_Boolean FW_LocaleIsSingleByte(FW_Locale locale)
- {
- #ifdef FW_BUILD_MAC
- return FW_MacScriptIsSingleByte(locale.fScriptCode);
- #elif defined FW_BUILD_WIN
- return true;
-
- // Someday, the code will look something like this:
- //CPINFO cpinfo;
- //GetACP(locale, &cpinfo);
- //return cpinfo.MaxCharSize == 1;
- // If GetACP might be expensive, it might be worthwhile mimicking the above
- // routine which caches the result of the last call.
- #endif
- }
-
- //========================================================================================
- // FW_CharIsDoubleByte
- //========================================================================================
-
- FW_Boolean FW_CharIsDoubleByte(const char* p, short offset, const FW_Locale& locale)
- {
- FW_Boolean result = false; // assume false, which will be the case for single-byte scripts
-
- #ifdef FW_BUILD_MAC
- if (!FW_LocaleIsSingleByte(locale))
- {
- Ptr textBuf = (Ptr) p;
- short byteType = ::CharacterByteType(textBuf, offset, locale.fScriptCode);
- if (byteType == smFirstByte)
- result = true;
- }
- #endif
-
- return result;
- }
-
-